<!-- wechat-callback.vue -->
<template>
  <div>
    登录成功，正在跳转...
  </div>
</template>

<script>
  import { getCodeImg, loginWechat } from '@/api/login'

  export default {
    data() {
      return {
        codeUrl: "",
        captchaEnabled: true,
        // 用户注册开关
        register: true,
        globalConfig: getApp().globalData.config,
        loginWechatForm: {
          code: "",
          state: ''
        }
      }
    },
    created() {
      this.handleLogin()
    },
    methods: {
     
      // 登录方法
      async handleLogin() {       
        this.$modal.loading("登录中，请耐心等待...")
        this.pwdLogin()
      },
      // 密码登录
      async pwdLogin() {
		const query = this.$route.query;
		console.log("wechat-callback, pwdLogin", query);
		const code = query.code;
		const state = query.state;
		this.loginWechatForm.code = code;
		this.loginWechatForm.state = state;
		console.log('loginWechatForm', this.loginWechatForm);
        this.$store.dispatch('LoginWechat', this.loginWechatForm).then(() => {
          this.$modal.closeLoading()
          this.loginSuccess()
        }).catch(() => {
          // if (this.captchaEnabled) {
          //   this.getCode()
          // }
        })
      },
      // 登录成功后，处理函数
      loginSuccess(result) {
        // 设置用户信息
        this.$store.dispatch('GetInfo').then(res => {
          this.$tab.reLaunch('/pages/index')
        })
      }
    }
  }
</script>

<style lang="scss">
  page {
    background-color: #ffffff;
  }

  .normal-login-container {
    width: 100%;

    .logo-content {
      width: 100%;
      font-size: 21px;
      text-align: center;
      padding-top: 15%;

      image {
        border-radius: 4px;
      }

      .title {
        margin-left: 10px;
      }
    }

    .login-form-content {
      text-align: center;
      margin: 20px auto;
      margin-top: 15%;
      width: 80%;

      .input-item {
        margin: 20px auto;
        background-color: #f5f6f7;
        height: 45px;
        border-radius: 20px;

        .icon {
          font-size: 38rpx;
          margin-left: 10px;
          color: #999;
        }

        .input {
          width: 100%;
          font-size: 14px;
          line-height: 20px;
          text-align: left;
          padding-left: 15px;
        }

      }

      .login-btn {
        margin-top: 40px;
        height: 45px;
      }
      
      .reg {
        margin-top: 15px;
      }
      
      .xieyi {
        color: #333;
        margin-top: 20px;
      }
      
      .login-code {
        height: 38px;
        float: right;
      
        .login-code-img {
          height: 38px;
          position: absolute;
          margin-left: 10px;
          width: 200rpx;
        }
      }
    }
  }

</style>
